import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'state.dart';
import 'components/question.dart';
import 'components/tabbar.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    final state = StateManager();
    return ChangeNotifierProvider.value(
      value: state,
      child: MaterialApp(
        title: 'Writing App',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const WritingPage(),
      ),
    );
  }
}

class WritingPage extends StatefulWidget {
  const WritingPage({super.key});

  @override
  State<WritingPage> createState() => _WritingPageState();
}

class _WritingPageState extends State<WritingPage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final state = context.watch<StateManager>();
    return Scaffold(
      appBar: AppBar(title: const Text("田世阳的作业")),

      //
      body: Column(children: [
        const TabbarWidget(),
        Expanded(child: QuestionList(questions: state.currentTab.questions)),
      ]),

      //
      floatingActionButton: FloatingActionButton(
        // 点击在当前激活的标签页中添加题目
        onPressed: () => state.addQuestion(),
        backgroundColor: Colors.blue,
        foregroundColor: Colors.white,
        shape: const CircleBorder(),
        child: const Icon(Icons.add, size: 36),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: Container(color: Colors.white, height: 88),
    );
  }
}
